package com.sqlcheck.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.sqlcheck.util.JsonUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;
import java.util.Map;

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName(value = "reports")
public class Report {

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @TableField("task_id")
    private Long taskId;

    @TableField("report_name")
    private String reportName;

    @TableField("report_type")
    private ReportType reportType;

    @TableField("file_path")
    private String filePath;

    @TableField("file_size")
    private Long fileSize;

    @TableField("generate_time")
    private LocalDateTime generateTime;

    @TableField("download_count")
    private Integer downloadCount;

    @TableField("summary")
    private String summaryJson;

    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private LocalDateTime createdAt;

    @TableLogic
    @TableField("deleted")
    private Boolean deleted;

    // Helper methods for summary JSON field
    public Map<String, Object> getSummary() {
        return JsonUtils.safeParseMap(this.summaryJson);
    }

    public Report setSummary(Map<String, Object> summary) {
        this.summaryJson = JsonUtils.safeToJsonString(summary);
        return this;
    }

    public enum ReportType {
        PDF, EXCEL, HTML, JSON
    }
}